package com.steamedfish.auctioncloudgatewayserver.filter;

import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


@Component
public class AccessFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //获取token参数
        String token = exchange.getRequest().getHeaders().getFirst("Authorization");
        if (StringUtils.isBlank(token)) {
            token = exchange.getRequest().getQueryParams().getFirst("Authorization");
        }


        System.out.println(token);

        //验证token是否合法



        //合法则放行，不合法则丢到兽群验证服务器

        return chain.filter(exchange);



    }

    @Override
    public int getOrder() {
        return 0;
    }
}